package com.em.baselibrary;

import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.TextView;

import com.em.baselistener.OnBackListener;
import com.em.baselistener.OnMoreListener;
import com.em.baselistener.OnTitleClickListener;

public class BaseFragmentActivity extends FragmentActivity{

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_base);
	}

	public void setTitle(String title) {
		TextView public_top_title_tv = (TextView) findViewById(R.id.public_top_title_tv);
		if (public_top_title_tv != null) {
			public_top_title_tv.setText(title);
		}
	}

	public void onTitleClick(final OnTitleClickListener listener) {
		TextView public_top_title_tv = (TextView) findViewById(R.id.public_top_title_tv);
		if (public_top_title_tv != null) {
			public_top_title_tv.setOnClickListener(new OnClickListener() {
				@Override
				public void onClick(View v) {
					listener.onTitleClick(v);
				}
			});
		}
	}

	public void onBackClick(final OnBackListener listener) {
		View public_top_title_back_panel = findViewById(R.id.public_top_title_back_panel);
		if (public_top_title_back_panel != null) {
			public_top_title_back_panel
					.setOnClickListener(new OnClickListener() {
						@Override
						public void onClick(View v) {
							// TODO Auto-generated method stub
							listener.onBackClick(v);
						}
					});
		}
	}

	public void onMoreClick(final OnMoreListener listener) {
		View public_actionbar_more = findViewById(R.id.public_actionbar_more);
		if (public_actionbar_more != null) {
			public_actionbar_more.setVisibility(View.VISIBLE);
			public_actionbar_more.setOnClickListener(new OnClickListener() {

				@Override
				public void onClick(View v) {
					if (listener != null) {
						listener.onMoreClick(v);
					}
				}
			});
		}
	}

	public void showMoreBtn(final OnMoreListener listener){
		View public_actionbar_more = findViewById(R.id.public_actionbar_more);
		if (public_actionbar_more!=null) {
			public_actionbar_more.setVisibility(View.VISIBLE);
			public_actionbar_more.setOnClickListener(new OnClickListener() {

				@Override
				public void onClick(View v) {
					if (listener!=null) {
						listener.onMoreClick(v);
					}
				}
			});
		}
	}
}
